//
//  LatestAnnouncedCell.m
//  NormalFramework
//
//  Created by beisheng03 on 2018/3/12.
//  Copyright © 2018年 beisheng. All rights reserved.
//

#import "LatestAnnouncedCell.h"

@interface LatestAnnouncedCell ()
@property (weak, nonatomic) IBOutlet UIImageView *topImageView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;

@property (weak, nonatomic) IBOutlet UILabel *numberLabel;
@property (weak, nonatomic) IBOutlet UILabel *imgRightLabel;
@property (weak, nonatomic) IBOutlet UIImageView *lockImageView;

@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@end
@implementation LatestAnnouncedCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.contentView.backgroundColor = [UIColor whiteColor];
    [self.topImageView sd_setImageWithURL:[NSURL URLWithString:@"http://img5.duitang.com/uploads/item/201502/19/20150219230250_NJnHx.jpeg"]];
    [self.lockImageView sd_setImageWithURL:[NSURL URLWithString:@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1521260813427&di=044bd64b746a11615545dc9cf6045bde&imgtype=0&src=http%3A%2F%2Fpic2.16pic.com%2F00%2F21%2F12%2F16pic_2112052_b.jpg"]];
    self.nameLabel.font = BigTitleFont;
    self.numberLabel.font = SubTitleFont;
    self.numberLabel.textColor = darkGray;
    self.imgRightLabel.font = SubTitleFont;
    self.imgRightLabel.textColor = themeColor;
    self.timeLabel.font = MYFONT(22);
    
    self.timeLabel.textColor = themeColor;
    
    // Initialization code
}



- (void)setTime:(NSInteger)time{
    _time = time;
    
    [self setupCreatedAtWithTimeValue:_time];
    
}


- (void)setupCreatedAtWithTimeValue:(NSInteger)timeValue
{
    
    NSInteger h = timeValue / 3600;
    
    NSInteger m = (timeValue % 3600) / 60;
    
    NSInteger s = timeValue % 60;
    
    
    if (s < 0) {
        self.timeLabel.text = @"00:00:00";
    } else {
        self.timeLabel.text = [NSString stringWithFormat:@"%.2ld:%.2ld:%.2ld",h,m,s];

    }
    
    
//        NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
//        fmt.dateFormat = @"yyyy-MM-dd HH:mm:ss";
//        NSLocale * locale = [NSLocale localeWithLocaleIdentifier:@"zh-CN"];
//        fmt.locale = locale;
//        NSDate *createdAtDate;
//        CGFloat s = timeValue;
//        createdAtDate = [NSDate dateWithTimeIntervalSinceNow:<#(NSTimeInterval)#>];
//        NSString *str = [fmt stringFromDate:createdAtDate];
//
//        NSLog(@"%@",str);
    
//        createdAtDate = [fmt dateFromString:str];
//
//        fmt.dateFormat = @"HH:mm:ss";
//        self.timeLabel.text = [fmt stringFromDate:createdAtDate];
//

    
    // 测试数据
//    NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
//    fmt.dateFormat = @"yyyy-MM-dd HH:mm:ss";
//
//    NSDate *createdAtDate;
//    CGFloat s = timeValue;
//    createdAtDate = [NSDate dateWithTimeIntervalSince1970:s];
//    NSString *str = [fmt stringFromDate:createdAtDate];
//    createdAtDate = [fmt dateFromString:str];
//
//    fmt.dateFormat = @"MM-dd HH:mm";
//    self.timeLabel.text = [fmt stringFromDate:createdAtDate];
    
    
    //    if (createdAtDate.isThisYear) { // 今年
    //        if (createdAtDate.isYesterday) { // 昨天
    //            if ([self.model.typname isEqualToString:@"local"]) {
    //                fmt.dateFormat = @"昨天";
    //
    //            } else {
    //                fmt.dateFormat = @"昨天 HH:mm";
    //
    //            }
    //            self.timeLabel.text = [fmt stringFromDate:createdAtDate];
    //        } else if (createdAtDate.isToday) { // 今天
    //            NSCalendarUnit unit = NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
    //            NSDateComponents *cmps = [[NSCalendar zm_calendar] components:unit fromDate:createdAtDate toDate:[NSDate date] options:0];
    //
    //            if (cmps.hour >= 1) { // 时间间隔 >= 1小时
    //                if ([self.model.typname isEqualToString:@"local"]) {
    //                    self.timeLabel.text = @"今天";
    //
    //                } else {
    //                    self.timeLabel.text = [NSString stringWithFormat:@"%zd小时前", cmps.hour];
    //
    //                }
    //            } else if (cmps.minute >= 1) { // 1小时 > 时间间隔 >= 1分钟
    //
    //                if ([self.model.typname isEqualToString:@"local"]) {
    //                    self.timeLabel.text = @"今天";
    //                } else {
    //                    self.timeLabel.text = [NSString stringWithFormat:@"%zd分钟前", cmps.minute];
    //
    //                }
    //            } else { // 1分钟 > 时间间隔
    //                if ([self.model.typname isEqualToString:@"local"]) {
    //                    self.timeLabel.text = @"今天";
    //
    //                } else {
    //                    self.timeLabel.text = @"刚刚";
    //
    //                }
    //            }
    //        } else { // 除昨天、今天以外，今年的其他天
    //            fmt.dateFormat = @"MM-dd HH:mm";
    //            self.timeLabel.text = [fmt stringFromDate:createdAtDate];
    //        }
    //    } else { // 非今年
    //        fmt.dateFormat = @"MM-dd";
    //        self.timeLabel.text = [fmt stringFromDate:createdAtDate];
    //    }
}



@end
